package com.skrabacz.kinetic.buisness.logic;

import javax.management.InvalidAttributeValueException;

public class Matrix implements Board {

	private Point[][] matrix;
	private int width;
	private int height;

	public Matrix() {
		this(new Node[1][1]);
	}

	public Matrix(int i, int j) {
		this(new Point[i][j]);
	}

	public Matrix(Point[][] matrix) {
		this.matrix = matrix;
	}

	@Override
	public Point getPoint(int... coordinate) throws InvalidAttributeValueException {
		// TODO msk: moved this checking to aspect
		checkCoordinates(coordinate);
		return matrix[coordinate[1]][coordinate[0]];
	}

	private void checkCoordinates(int... coordinate) {
		if (coordinate[0] > width || coordinate[1] > height) {
			throw new IndexOutOfBoundsException();
		}
	}

	public void updateMatrixParams() {
		height = matrix.length;
		width = matrix[0].length;
	}

	@Override
	public int getWidth() {
		return width;
	}

	@Override
	public int getHeight() {
		return height;
	}

}
